package com.eflow.model.flowable.utils;

import com.eflow.model.flowable.model.e.BaseEnum;
import org.apache.commons.lang3.EnumUtils;

import java.util.List;

/**
 * @author hui se
 * @description
 * @create 2021-03-05 17:57
 **/
public class BaseEnumUtil {
    public static boolean isImplementsBaseEnum(Class clz) {
        return BaseEnum.class.isAssignableFrom(clz);
    }

     public static Enum convertToEnum(Class clz, int intValue) {
        if(!isImplementsBaseEnum(clz)){
            throw new RuntimeException("class not is BaseEnum");
        }
        List<BaseEnum> enumList = EnumUtils.getEnumList(clz);
        for (BaseEnum e : enumList) {
            if(e.getCode()==intValue){
                return  (Enum)e;
            }
        }
        return null;
    }
}
